package com.lc.luzhengtang.adapter;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.lc.luzhengtang.R;
import com.lc.luzhengtang.bean.ShopDetailBean;
import com.lc.luzhengtang.conn.Conn;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

import static com.lc.luzhengtang.R.id.text_newstitle;

/**
 * 文 件 名: NewsListAdapter
 * 创 建 人: zhangyu
 * 创建日期: 16/12/24 19:55
 * 邮   箱: yuanchong121@gmail.com
 * 修改时间：
 * 修改备注：
 */
public class EvaluateListAdapter2 extends RecyclerView.Adapter<EvaluateListAdapter2.ViewHolder> implements View.OnClickListener {

    private Context context;
    private List<ShopDetailBean.DataBeanX.EvaluateBean.DataBean> list;

    ItemPicAdapter2 itemPicAdapter2;

    public EvaluateListAdapter2(Context context, List<ShopDetailBean.DataBeanX.EvaluateBean.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public void onClick(View v) {

    }

    // Provide a reference to the views for each data item
    // Complex data items may need more than one view per item, and
    // you provide access to all the views for a data item in a view holder
    public static class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.img_person)
        SimpleDraweeView imgPerson;
        @BindView(R.id.text_newstime)
        TextView textNewstime;
        @BindView(text_newstitle)
        TextView textNewstitle;
        @BindView(R.id.text_tiem)
        TextView textTiem;
        @BindView(R.id.text_content)
        TextView textContent;
        @BindView(R.id.layout_grid)
        GridView layoutGrid;
        @BindView(R.id.layout_xinxi)
        LinearLayout layoutXinxi;
        @BindView(R.id.recyclerView_photolist)
        RecyclerView recyclerViewPhotolist;
        @BindView(R.id.list_comment)
        ListView listComment;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
       /* View view = BoundViewHelper.boundView(this, MyApplication.scaleScreenHelper.loadView((ViewGroup) LayoutInflater.from(parent.getContext())
                .inflate(R.layout.list_02_item_view, null)));*/
        View view = BoundViewHelper.boundView(this, ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) LayoutInflater.from(context)
                .inflate(R.layout.item_evaluate, null)));
        ViewHolder vh = new ViewHolder(view);


        return vh;
    }


    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
//        GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 4);
        holder.recyclerViewPhotolist.setLayoutManager(new GridLayoutManager(context, 4));

        itemPicAdapter2 = new ItemPicAdapter2(context, list.get(position).getPicarr(), this);
        if (list.get(position).getPicarr().isEmpty()) {
            holder.recyclerViewPhotolist.setVisibility(View.GONE);
        } else {
            holder.recyclerViewPhotolist.setAdapter(itemPicAdapter2);
        }
        holder.imgPerson.setImageURI(Conn.HOST3 + list.get(position).getAvatar());

//        Glide.with(context).load(Conn.HOST3 + list.get(position).getAvatar()).transform(new GlideCircleTransform(context)).error(R.mipmap.touxiang).placeholder(R.mipmap.touxiang).into(holder.imgPerson);
//        Glide.with(context).load(Conn.HOST3 + list.get(position).getAvatar()).transform(new com.lc.luzhengtang.imgloader.GlideCircleTransform(mContext)).error(R.mipmap.touxiang).placeholder(R.mipmap.touxiang).into(holder.imgPerson);
//        Glide.with(mContext).load(Conn.HOST3 + item.getAvatar()).transform(new com.lc.luzhengtang.imgloader.GlideCircleTransform(mContext)).error(R.mipmap.touxiang).placeholder(R.mipmap.touxiang).into((ImageView) helper.getView(R.id.img_person));
        holder.textNewstime.setText(list.get(position).getUsername());
//        text_newstitle
        holder.textNewstitle.setText(list.get(position).getEval());
        holder.textTiem.setText(list.get(position).getCreate_time());
        holder.textContent.setText(list.get(position).getContent());


    }

    /**
     * Returns the total number of items in the data set hold by the adapter.
     *
     * @return The total number of items in this adapter.
     */
    @Override
    public int getItemCount() {

        if (list.size() >= 2) {
            return 2;
        } else {
            return list.size();
        }

    }


}
